// 生成随机组，每组24个和25个数，确保唯一
export const generateTwentyfourRandomArray = (startIndex, count, padLength = 4, historicalData = []) => {
  // 随机函数，生成分组
  const generateSortedRandomGroups = (existingGroupsSet) => {
    const numbers = Array.from({ length: 49 }, (_, i) => i + 1) // 生成1到49的数组

    let groups = []
    let attempts = 0

    while (groups.length < 2) {
      // 目标是生成2个组
      const shuffled = numbers.sort(() => Math.random() - 0.5) // 打乱顺序

      const group1 = shuffled.slice(0, 24).sort((a, b) => a - b) // 前24个
      const group2 = shuffled.slice(24).sort((a, b) => a - b) // 后25个

      const tempGroups = [group1, group2]

      // 转换为字符串形式，检查是否重复
      const tempGroupsStr = tempGroups.map((group) => JSON.stringify(group))
      const isUnique = tempGroupsStr.every((groupStr) => !existingGroupsSet.has(groupStr))

      if (isUnique) {
        tempGroupsStr.forEach((groupStr) => existingGroupsSet.add(groupStr))
        groups = tempGroups
      }

      attempts++
      if (attempts > 1000) break // 防止死循环
    }

    return groups
  }

  // 将历史数据转换为 Set，避免重复
  const existingGroupsSet = new Set()
  historicalData.forEach((group) => {
    const groupStr = JSON.stringify(group)
    existingGroupsSet.add(groupStr)
  })

  // 随机分组
  const generateRangeGroups = () => {
    const groups = {}

    for (let i = startIndex; i < startIndex + count; i++) {
      const key = `TWENTYFOUR_RANGE_${String(i).padStart(padLength, '0')}_GROUPS`
      groups[key] = generateSortedRandomGroups(existingGroupsSet)
    }

    return groups
  }

  return generateRangeGroups()
}

// 生成随机组，每组16个和17个数，确保唯一
export const generateSixteenRandomArray = (startIndex, count, padLength = 4, historicalData = []) => {
  // 随机函数，生成分组
  const generateSortedRandomGroups = (existingGroupsSet) => {
    const numbers = Array.from({ length: 49 }, (_, i) => i + 1) // 生成1到49的数组

    let groups = []
    let attempts = 0

    // 循环确保生成的每组数据独一无二
    while (groups.length < 3) {
      // 目标是生成3个组
      // 打乱顺序
      const shuffled = numbers.sort(() => Math.random() - 0.5)

      // 按照16，16，17分组
      const group1 = shuffled.slice(0, 16).sort((a, b) => a - b) // 前16个
      const group2 = shuffled.slice(16, 32).sort((a, b) => a - b) // 后16个
      const group3 = shuffled.slice(32).sort((a, b) => a - b) // 剩下17个

      const tempGroups = [group1, group2, group3]

      // 转换为字符串形式，检查是否重复
      const tempGroupsStr = tempGroups.map((group) => JSON.stringify(group))
      const isUnique = tempGroupsStr.every((groupStr) => !existingGroupsSet.has(groupStr))

      if (isUnique) {
        tempGroupsStr.forEach((groupStr) => existingGroupsSet.add(groupStr)) // 添加到已存在集合
        groups = tempGroups // 更新当前分组
      }

      attempts++
      if (attempts > 1000) break // 防止死循环
    }

    return groups
  }

  // 将历史数据转换为 Set，避免重复
  const existingGroupsSet = new Set()
  historicalData.forEach((group) => {
    const groupStr = JSON.stringify(group)
    existingGroupsSet.add(groupStr)
  })

  // 随机分组
  const generateRangeGroups = () => {
    const groups = {}

    for (let i = startIndex; i < startIndex + count; i++) {
      const key = `SIXTEEN_RANGE_${String(i).padStart(padLength, '0')}_GROUPS`
      groups[key] = generateSortedRandomGroups(existingGroupsSet)
    }

    return groups
  }

  // 执行生成
  const rangeGroups = generateRangeGroups()
  // console.group(moment().format('YYYY-MM-DD_HH-mm-ss') + ' Sixteen Range Groups')
  // console.log(rangeGroups)
  // console.groupEnd()

  return rangeGroups
}

// 生成随机组，每组12个、12个、12个和13个数，确保唯一
export const generateTwelveRandomArray = (startIndex, count, padLength = 4, historicalData = []) => {
  // 随机函数，生成分组
  const generateSortedRandomGroups = (existingGroupsSet) => {
    const numbers = Array.from({ length: 49 }, (_, i) => i + 1) // 生成1到49的数组

    let groups = []
    let attempts = 0

    while (groups.length < 4) {
      // 目标是生成4个组
      const shuffled = numbers.sort(() => Math.random() - 0.5) // 打乱顺序

      const group1 = shuffled.slice(0, 12).sort((a, b) => a - b) // 前12个
      const group2 = shuffled.slice(12, 24).sort((a, b) => a - b) // 中间12个
      const group3 = shuffled.slice(24, 36).sort((a, b) => a - b) // 后12个
      const group4 = shuffled.slice(36).sort((a, b) => a - b) // 剩下13个

      const tempGroups = [group1, group2, group3, group4]

      // 转换为字符串形式，检查是否重复
      const tempGroupsStr = tempGroups.map((group) => JSON.stringify(group))
      const isUnique = tempGroupsStr.every((groupStr) => !existingGroupsSet.has(groupStr))

      if (isUnique) {
        tempGroupsStr.forEach((groupStr) => existingGroupsSet.add(groupStr))
        groups = tempGroups
      }

      attempts++
      if (attempts > 1000) break // 防止死循环
    }

    return groups
  }

  // 将历史数据转换为 Set，避免重复
  const existingGroupsSet = new Set()
  historicalData.forEach((group) => {
    const groupStr = JSON.stringify(group)
    existingGroupsSet.add(groupStr)
  })

  // 随机分组
  const generateRangeGroups = () => {
    const groups = {}

    for (let i = startIndex; i < startIndex + count; i++) {
      const key = `TWELVE_RANGE_${String(i).padStart(padLength, '0')}_GROUPS`
      groups[key] = generateSortedRandomGroups(existingGroupsSet)
    }

    return groups
  }

  return generateRangeGroups()
}

// 生成随机组，每组10个、10个、10个、10个和9个数，确保唯一
export const generateTenRandomArray = (startIndex, count, padLength = 4, historicalData = []) => {
  // 随机函数，生成分组
  const generateSortedRandomGroups = (existingGroupsSet) => {
    const numbers = Array.from({ length: 49 }, (_, i) => i + 1) // 生成1到49的数组

    let groups = []
    let attempts = 0

    while (groups.length < 5) {
      // 目标是生成5个组
      const shuffled = numbers.sort(() => Math.random() - 0.5) // 打乱顺序

      const group1 = shuffled.slice(0, 10).sort((a, b) => a - b) // 前10个
      const group2 = shuffled.slice(10, 20).sort((a, b) => a - b) // 第二个10个
      const group3 = shuffled.slice(20, 30).sort((a, b) => a - b) // 第三个10个
      const group4 = shuffled.slice(30, 40).sort((a, b) => a - b) // 第四个10个
      const group5 = shuffled.slice(40).sort((a, b) => a - b) // 剩下的9个

      const tempGroups = [group1, group2, group3, group4, group5]

      // 转换为字符串形式，检查是否重复
      const tempGroupsStr = tempGroups.map((group) => JSON.stringify(group))
      const isUnique = tempGroupsStr.every((groupStr) => !existingGroupsSet.has(groupStr))

      if (isUnique) {
        tempGroupsStr.forEach((groupStr) => existingGroupsSet.add(groupStr))
        groups = tempGroups
      }

      attempts++
      if (attempts > 1000) break // 防止死循环
    }

    return groups
  }

  // 将历史数据转换为 Set，避免重复
  const existingGroupsSet = new Set()
  historicalData.forEach((group) => {
    const groupStr = JSON.stringify(group)
    existingGroupsSet.add(groupStr)
  })

  // 随机分组
  const generateRangeGroups = () => {
    const groups = {}

    for (let i = startIndex; i < startIndex + count; i++) {
      const key = `TEN_RANGE_${String(i).padStart(padLength, '0')}_GROUPS`
      groups[key] = generateSortedRandomGroups(existingGroupsSet)
    }

    return groups
  }

  return generateRangeGroups()
}

// 生成随机组，每组8个、8个、8个、8个、8个和9个数，确保唯一
export const generateEightRandomArray = (startIndex, count, padLength = 4, historicalData = []) => {
  // 随机函数，生成分组
  const generateSortedRandomGroups = (existingGroupsSet) => {
    const numbers = Array.from({ length: 49 }, (_, i) => i + 1) // 生成1到49的数组

    let groups = []
    let attempts = 0

    while (groups.length < 6) {
      // 目标是生成6个组
      const shuffled = numbers.sort(() => Math.random() - 0.5) // 打乱顺序

      const group1 = shuffled.slice(0, 8).sort((a, b) => a - b) // 前8个
      const group2 = shuffled.slice(8, 16).sort((a, b) => a - b) // 第二个8个
      const group3 = shuffled.slice(16, 24).sort((a, b) => a - b) // 第三个8个
      const group4 = shuffled.slice(24, 32).sort((a, b) => a - b) // 第四个8个
      const group5 = shuffled.slice(32, 40).sort((a, b) => a - b) // 第五个8个
      const group6 = shuffled.slice(40).sort((a, b) => a - b) // 剩下的9个

      const tempGroups = [group1, group2, group3, group4, group5, group6]

      // 转换为字符串形式，检查是否重复
      const tempGroupsStr = tempGroups.map((group) => JSON.stringify(group))
      const isUnique = tempGroupsStr.every((groupStr) => !existingGroupsSet.has(groupStr))

      if (isUnique) {
        tempGroupsStr.forEach((groupStr) => existingGroupsSet.add(groupStr))
        groups = tempGroups
      }

      attempts++
      if (attempts > 1000) break // 防止死循环
    }

    return groups
  }

  // 将历史数据转换为 Set，避免重复
  const existingGroupsSet = new Set()
  historicalData.forEach((group) => {
    const groupStr = JSON.stringify(group)
    existingGroupsSet.add(groupStr)
  })

  // 随机分组
  const generateRangeGroups = () => {
    const groups = {}

    for (let i = startIndex; i < startIndex + count; i++) {
      const key = `EIGHT_RANGE_${String(i).padStart(padLength, '0')}_GROUPS`
      groups[key] = generateSortedRandomGroups(existingGroupsSet)
    }

    return groups
  }

  return generateRangeGroups()
}

// 生成随机组，每组7个数，总共7组，确保唯一
export const generateSevenRandomArray = (startIndex, count, padLength = 4, historicalData = []) => {
  // 随机函数，生成分组
  const generateSortedRandomGroups = (existingGroupsSet) => {
    const numbers = Array.from({ length: 49 }, (_, i) => i + 1) // 生成1到49的数组

    let groups = []
    let attempts = 0

    while (groups.length < 7) {
      // 目标是生成7个组
      const shuffled = numbers.sort(() => Math.random() - 0.5) // 打乱顺序

      const group1 = shuffled.slice(0, 7).sort((a, b) => a - b) // 前7个
      const group2 = shuffled.slice(7, 14).sort((a, b) => a - b) // 第二个7个
      const group3 = shuffled.slice(14, 21).sort((a, b) => a - b) // 第三个7个
      const group4 = shuffled.slice(21, 28).sort((a, b) => a - b) // 第四个7个
      const group5 = shuffled.slice(28, 35).sort((a, b) => a - b) // 第五个7个
      const group6 = shuffled.slice(35, 42).sort((a, b) => a - b) // 第六个7个
      const group7 = shuffled.slice(42).sort((a, b) => a - b) // 剩下的7个

      const tempGroups = [group1, group2, group3, group4, group5, group6, group7]

      // 转换为字符串形式，检查是否重复
      const tempGroupsStr = tempGroups.map((group) => JSON.stringify(group))
      const isUnique = tempGroupsStr.every((groupStr) => !existingGroupsSet.has(groupStr))

      if (isUnique) {
        tempGroupsStr.forEach((groupStr) => existingGroupsSet.add(groupStr))
        groups = tempGroups
      }

      attempts++
      if (attempts > 1000) break // 防止死循环
    }

    return groups
  }

  // 将历史数据转换为 Set，避免重复
  const existingGroupsSet = new Set()
  historicalData.forEach((group) => {
    const groupStr = JSON.stringify(group)
    existingGroupsSet.add(groupStr)
  })

  // 随机分组
  const generateRangeGroups = () => {
    const groups = {}

    for (let i = startIndex; i < startIndex + count; i++) {
      const key = `SEVEN_RANGE_${String(i).padStart(padLength, '0')}_GROUPS`
      groups[key] = generateSortedRandomGroups(existingGroupsSet)
    }

    return groups
  }

  return generateRangeGroups()
}

// 生成随机组，每组6个数，总共7组，确保唯一
export const generateSixRandomArray = (startIndex, count, padLength = 4, historicalData = []) => {
  // 随机函数，生成分组
  const generateSortedRandomGroups = (existingGroupsSet) => {
    const numbers = Array.from({ length: 49 }, (_, i) => i + 1) // 生成1到49的数组

    let groups = []
    let attempts = 0

    while (groups.length < 8) {
      // 目标是生成7个组
      const shuffled = numbers.sort(() => Math.random() - 0.5) // 打乱顺序

      const group1 = shuffled.slice(0, 6).sort((a, b) => a - b) // 前6个
      const group2 = shuffled.slice(6, 12).sort((a, b) => a - b) // 第二个6个
      const group3 = shuffled.slice(12, 18).sort((a, b) => a - b) // 第三个6个
      const group4 = shuffled.slice(18, 24).sort((a, b) => a - b) // 第四个6个
      const group5 = shuffled.slice(24, 30).sort((a, b) => a - b) // 第五个6个
      const group6 = shuffled.slice(30, 36).sort((a, b) => a - b) // 第六个6个
      const group7 = shuffled.slice(36, 42).sort((a, b) => a - b) // 第六个6个
      const group8 = shuffled.slice(42).sort((a, b) => a - b) // 剩下的7个

      const tempGroups = [group1, group2, group3, group4, group5, group6, group7, group8]

      // 转换为字符串形式，检查是否重复
      const tempGroupsStr = tempGroups.map((group) => JSON.stringify(group))
      const isUnique = tempGroupsStr.every((groupStr) => !existingGroupsSet.has(groupStr))

      if (isUnique) {
        tempGroupsStr.forEach((groupStr) => existingGroupsSet.add(groupStr))
        groups = tempGroups
      }

      attempts++
      if (attempts > 1000) break // 防止死循环
    }

    return groups
  }

  // 将历史数据转换为 Set，避免重复
  const existingGroupsSet = new Set()
  historicalData.forEach((group) => {
    const groupStr = JSON.stringify(group)
    existingGroupsSet.add(groupStr)
  })

  // 随机分组
  const generateRangeGroups = () => {
    const groups = {}

    for (let i = startIndex; i < startIndex + count; i++) {
      const key = `SIX_RANGE_${String(i).padStart(padLength, '0')}_GROUPS`
      groups[key] = generateSortedRandomGroups(existingGroupsSet)
    }

    return groups
  }

  return generateRangeGroups()
}

// 生成随机组, 每组5个数
export const generateFiveRandomArray = (startIndex, count, padLength = 4, historicalData = []) => {
  // 随机函数
  const generateSortedRandomGroups = (existingGroupsSet) => {
    const numbers = Array.from({ length: 49 }, (_, i) => i + 1)

    let groups = []
    let attempts = 0

    // 循环确保生成的每组数据独一无二
    while (groups.length < 10) {
      // 打乱顺序
      const shuffled = numbers.sort(() => Math.random() - 0.5)

      // 分组，并对子数组升序排序
      const tempGroups = []
      for (let i = 0; i < shuffled.length; i += 5) {
        const group = shuffled.slice(i, i + 5).sort((a, b) => a - b)
        tempGroups.push(group)
      }

      // 按子数组首个元素排序
      tempGroups.sort((a, b) => a[0] - b[0])

      // 转换为字符串形式，检查是否重复
      const tempGroupsStr = tempGroups.map((group) => JSON.stringify(group))
      const isUnique = tempGroupsStr.every((groupStr) => !existingGroupsSet.has(groupStr))

      if (isUnique) {
        tempGroupsStr.forEach((groupStr) => existingGroupsSet.add(groupStr)) // 添加到已存在集合
        groups = tempGroups // 更新当前分组
      }

      attempts++
      if (attempts > 1000) break // 防止死循环
    }

    return groups
  }

  // 将历史数据转换为 Set，避免重复
  const existingGroupsSet = new Set()
  historicalData.forEach((group) => {
    const groupStr = JSON.stringify(group)
    existingGroupsSet.add(groupStr)
  })

  // 随机分组
  const generateRangeGroups = () => {
    const groups = {}

    for (let i = startIndex; i < startIndex + count; i++) {
      const key = `FIVE_RANGE_${String(i).padStart(padLength, '0')}_GROUPS`
      groups[key] = generateSortedRandomGroups(existingGroupsSet)
    }

    return groups
  }

  // 执行生成
  const rangeGroups = generateRangeGroups()
  // console.group(moment().format('YYYY-MM-DD_HH-mm-ss') + ' Five Range Groups')
  // console.log(rangeGroups)
  // console.groupEnd()

  return rangeGroups
}

// 生成随机组，每组4个数，总共12组，确保唯一
export const generateFourRandomArray = (startIndex, count, padLength = 4, historicalData = []) => {
  // 随机函数，生成分组
  const generateSortedRandomGroups = (existingGroupsSet) => {
    const numbers = Array.from({ length: 49 }, (_, i) => i + 1) // 生成1到49的数组

    let groups = []
    let attempts = 0

    while (groups.length < 12) {
      // 目标是生成12个组
      const shuffled = numbers.sort(() => Math.random() - 0.5) // 打乱顺序

      const group1 = shuffled.slice(0, 4).sort((a, b) => a - b) // 前4个
      const group2 = shuffled.slice(4, 8).sort((a, b) => a - b) // 第二个4个
      const group3 = shuffled.slice(8, 12).sort((a, b) => a - b) // 第三个4个
      const group4 = shuffled.slice(12, 16).sort((a, b) => a - b) // 第四个4个
      const group5 = shuffled.slice(16, 20).sort((a, b) => a - b) // 第五个4个
      const group6 = shuffled.slice(20, 24).sort((a, b) => a - b) // 第六个4个
      const group7 = shuffled.slice(24, 28).sort((a, b) => a - b) // 第七个4个
      const group8 = shuffled.slice(28, 32).sort((a, b) => a - b) // 第八个4个
      const group9 = shuffled.slice(32, 36).sort((a, b) => a - b) // 第九个4个
      const group10 = shuffled.slice(36, 40).sort((a, b) => a - b) // 第十个4个
      const group11 = shuffled.slice(40, 44).sort((a, b) => a - b) // 第十一个4个
      const group12 = shuffled.slice(44).sort((a, b) => a - b) // 剩下的5个

      const tempGroups = [
        group1,
        group2,
        group3,
        group4,
        group5,
        group6,
        group7,
        group8,
        group9,
        group10,
        group11,
        group12
      ]

      // 转换为字符串形式，检查是否重复
      const tempGroupsStr = tempGroups.map((group) => JSON.stringify(group))
      const isUnique = tempGroupsStr.every((groupStr) => !existingGroupsSet.has(groupStr))

      if (isUnique) {
        tempGroupsStr.forEach((groupStr) => existingGroupsSet.add(groupStr))
        groups = tempGroups
      }

      attempts++
      if (attempts > 1000) break // 防止死循环
    }

    return groups
  }

  // 将历史数据转换为 Set，避免重复
  const existingGroupsSet = new Set()
  historicalData.forEach((group) => {
    const groupStr = JSON.stringify(group)
    existingGroupsSet.add(groupStr)
  })

  // 随机分组
  const generateRangeGroups = () => {
    const groups = {}

    for (let i = startIndex; i < startIndex + count; i++) {
      const key = `FOUR_RANGE_${String(i).padStart(padLength, '0')}_GROUPS`
      groups[key] = generateSortedRandomGroups(existingGroupsSet)
    }

    return groups
  }

  return generateRangeGroups()
}

export const generateThreeRandomArray = (startIndex, count, padLength = 4, historicalData = []) => {
  // 随机函数，生成分组
  const generateSortedRandomGroups = (existingGroupsSet) => {
    const numbers = Array.from({ length: 49 }, (_, i) => i + 1) // 生成1到49的数组

    let groups = []
    let attempts = 0

    while (groups.length < 16 && attempts < 1000) {
      // 目标是生成16个组
      const shuffled = [...numbers].sort(() => Math.random() - 0.5) // 打乱顺序，避免原数组影响

      // 生成15个3个数字的组
      const tempGroups = []
      for (let i = 0; i < 15; i++) {
        const group = shuffled.slice(i * 3, i * 3 + 3).sort((a, b) => a - b)
        // 只保留符合要求的分组
        if (group.length === 3) tempGroups.push(group)
      }

      // 最后1组包含4个数字
      const group16 = shuffled.slice(45, 49).sort((a, b) => a - b) // 剩下的4个数字
      if (group16.length === 4) tempGroups.push(group16)

      // 过滤掉空数组，确保每个组都有数据
      const nonEmptyGroups = tempGroups.filter((group) => group.length === 3 || group.length === 4)

      // 确保总共生成16个有效分组
      if (nonEmptyGroups.length === 16) {
        // 转换为字符串形式，检查是否重复
        const tempGroupsStr = nonEmptyGroups.map((group) => JSON.stringify(group))
        const isUnique = tempGroupsStr.every((groupStr) => !existingGroupsSet.has(groupStr))

        if (isUnique) {
          tempGroupsStr.forEach((groupStr) => existingGroupsSet.add(groupStr)) // 加入已存在集合
          groups = nonEmptyGroups // 更新当前分组
        }
      }

      attempts++
      if (attempts > 1000) break // 防止死循环
    }

    return groups
  }

  // 将历史数据转换为 Set，避免重复
  const existingGroupsSet = new Set()
  historicalData.forEach((group) => {
    const groupStr = JSON.stringify(group)
    existingGroupsSet.add(groupStr)
  })

  // 随机分组
  const generateRangeGroups = () => {
    const groups = {}

    for (let i = startIndex; i < startIndex + count; i++) {
      const key = `THREE_RANGE_${String(i).padStart(padLength, '0')}_GROUPS`
      const value = generateSortedRandomGroups(existingGroupsSet)

      // 判断生成的 value 是否为空数组，如果为空则跳过
      if (value.length > 0) {
        groups[key] = value
      }
    }

    return groups
  }

  return generateRangeGroups()
}

export const generateTwoRandomArray = (startIndex, count, padLength = 4, historicalData = []) => {
  // 随机函数，生成分组
  const generateSortedRandomGroups = (existingGroupsSet) => {
    const numbers = Array.from({ length: 49 }, (_, i) => i + 1) // 生成1到49的数组

    let groups = []
    let attempts = 0

    // 生成分组，直到满足条件
    while (groups.length < 24 && attempts < 1000) {
      // 目标是生成24个组，避免死循环
      const shuffled = numbers.sort(() => Math.random() - 0.5) // 打乱顺序

      // 生成23个2个数字的组
      const group1 = shuffled.slice(0, 2).sort((a, b) => a - b)
      const group2 = shuffled.slice(2, 4).sort((a, b) => a - b)
      const group3 = shuffled.slice(4, 6).sort((a, b) => a - b)
      const group4 = shuffled.slice(6, 8).sort((a, b) => a - b)
      const group5 = shuffled.slice(8, 10).sort((a, b) => a - b)
      const group6 = shuffled.slice(10, 12).sort((a, b) => a - b)
      const group7 = shuffled.slice(12, 14).sort((a, b) => a - b)
      const group8 = shuffled.slice(14, 16).sort((a, b) => a - b)
      const group9 = shuffled.slice(16, 18).sort((a, b) => a - b)
      const group10 = shuffled.slice(18, 20).sort((a, b) => a - b)
      const group11 = shuffled.slice(20, 22).sort((a, b) => a - b)
      const group12 = shuffled.slice(22, 24).sort((a, b) => a - b)
      const group13 = shuffled.slice(24, 26).sort((a, b) => a - b)
      const group14 = shuffled.slice(26, 28).sort((a, b) => a - b)
      const group15 = shuffled.slice(28, 30).sort((a, b) => a - b)
      const group16 = shuffled.slice(30, 32).sort((a, b) => a - b)
      const group17 = shuffled.slice(32, 34).sort((a, b) => a - b)
      const group18 = shuffled.slice(34, 36).sort((a, b) => a - b)
      const group19 = shuffled.slice(36, 38).sort((a, b) => a - b)
      const group20 = shuffled.slice(38, 40).sort((a, b) => a - b)
      const group21 = shuffled.slice(40, 42).sort((a, b) => a - b)
      const group22 = shuffled.slice(42, 44).sort((a, b) => a - b)
      const group23 = shuffled.slice(44, 46).sort((a, b) => a - b)

      // 最后1组包含3个数字
      const group24 = shuffled.slice(46, 49).sort((a, b) => a - b)

      // 组合所有的组
      const tempGroups = [
        group1,
        group2,
        group3,
        group4,
        group5,
        group6,
        group7,
        group8,
        group9,
        group10,
        group11,
        group12,
        group13,
        group14,
        group15,
        group16,
        group17,
        group18,
        group19,
        group20,
        group21,
        group22,
        group23,
        group24
      ]

      // 检查是否为空组
      const nonEmptyGroups = tempGroups.filter((group) => group.length > 0)

      // 如果非空组的数量是 24，进行唯一性检查
      if (nonEmptyGroups.length === 24) {
        // 转换为字符串形式，检查是否重复
        const tempGroupsStr = nonEmptyGroups.map((group) => JSON.stringify(group))
        const isUnique = tempGroupsStr.every((groupStr) => !existingGroupsSet.has(groupStr))

        if (isUnique) {
          nonEmptyGroups.forEach((groupStr) => existingGroupsSet.add(groupStr)) // 加入已存在集合
          groups = nonEmptyGroups // 更新当前分组
        }
      }

      attempts++
      if (attempts > 1000) break // 防止死循环
    }

    return groups
  }

  // 将历史数据转换为 Set，避免重复
  const existingGroupsSet = new Set()
  historicalData.forEach((group) => {
    const groupStr = JSON.stringify(group)
    existingGroupsSet.add(groupStr)
  })

  // 随机分组
  const generateRangeGroups = () => {
    const groups = {}

    for (let i = startIndex; i < startIndex + count; i++) {
      const key = `TWO_RANGE_${String(i).padStart(padLength, '0')}_GROUPS`
      groups[key] = generateSortedRandomGroups(existingGroupsSet)
    }

    return groups
  }

  return generateRangeGroups()
}

// 随机函数映射对象
export const randomFnMap = {
  two: generateTwoRandomArray,
  three: generateThreeRandomArray,
  four: generateFourRandomArray,
  five: generateFiveRandomArray,
  six: generateSixRandomArray,
  seven: generateSevenRandomArray,
  eight: generateEightRandomArray,
  ten: generateTenRandomArray,
  twelve: generateTwelveRandomArray,
  sixteen: generateSixteenRandomArray,
  twentyfour: generateTwentyfourRandomArray
}
